package spring.boot.activemq.send.controller;



import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.jms.Destination;
import java.util.Date;

@RestController
@RequestMapping("/dev")
public class DevController {

    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @RequestMapping("/mq")
    public String mq(){
        String msg ="MQ测试消息 Queue"+new Date();
        Destination destination = new ActiveMQQueue("hello");
        jmsMessagingTemplate.convertAndSend(destination, msg);
        System.out.println("==send queue=="+msg);
        return "mq";
    }


    @RequestMapping("/topic")
    public String topic(){
        String msg ="MQ测试消息 Topic"+new Date();
        Destination destination = new ActiveMQTopic("topic");
        jmsMessagingTemplate.convertAndSend(destination, msg);
        System.out.println("==send topic=="+msg);
        return "mq";
    }

}
